<template>
  <el-container>
    <el-header>
      <el-menu
        :default-active="activeMenu"
        mode="horizontal"
        @select="handleMenuSelect"
      >
        <el-menu-item index="home">首页</el-menu-item>
        <el-menu-item index="archive">归档</el-menu-item>
        <el-menu-item index="message">留言板</el-menu-item>
        <el-menu-item index="admin" style="float: right">后台管理</el-menu-item>
      </el-menu>
    </el-header>
    <el-main>
      <el-row :gutter="20">
        <el-col :span="16">
          <ArticleList />
        </el-col>
        <el-col :span="8">
          <Sidebar />
        </el-col>
      </el-row>
    </el-main>
  </el-container>
</template>

<script setup>
import { ref } from 'vue'
import ArticleList from '../components/ArticleList.vue'
import Sidebar from '../components/Sidebar.vue'

const activeMenu = ref('home')
const handleMenuSelect = (index) => {
  if (index === 'admin') {
    window.location.href = '/login'
  } else if (index === 'home') {
    window.location.href = '/'
  } else {
    window.location.href = '/' + index
  }
}
</script>
